import request from '@/utils/request';
import { KnowledgeMockAPI } from './mock';

// 是否使用Mock数据（开发时可设置为true）
const USE_MOCK = false;

export const dirTree = (): Promise<any> => {
  if (USE_MOCK) {
    return Promise.resolve(KnowledgeMockAPI.getDirTree({}));
  }
  return request({
    url: '/kb/get_directory',
    method: 'post'
  });
};
export const firTree = (data: any): Promise<any> => {
  if (USE_MOCK) {
    return Promise.resolve(KnowledgeMockAPI.getFirTree(data));
  }
  return request({
    url: '/document/firTree',
    method: 'post',
    data: data
  });
};

export const dir = (data: any): Promise<any> => {
  if (USE_MOCK) {
    return Promise.resolve(KnowledgeMockAPI.createDir(data));
  }
  return request({
    url: '/document/dir',
    method: 'post',
    data: data
  });
};

export const fragments = (data: { kb_path: string }): Promise<any> => {
  if (USE_MOCK) {
    return Promise.resolve(KnowledgeMockAPI.getFragments(data));
  }
  return request({
    url: '/kb/list_directory',
    method: 'post',
    data: data
  });
};

export const fragmentContent = (data: any): Promise<any> => {
  if (USE_MOCK) {
    return Promise.resolve(KnowledgeMockAPI.getFirTree(data));
  }
  return request({
    url: '/document/fragmentContent',
    method: 'post',
    data: data
  });
};

export const editfragmentContent = (data: any): Promise<any> => {
  if (USE_MOCK) {
    return Promise.resolve(KnowledgeMockAPI.editFragmentContent(data));
  }
  return request({
    url: '/document/editfragmentContent',
    method: 'post',
    data: data
  });
};

export const deletefragment = (data: any): Promise<any> => {
  if (USE_MOCK) {
    return Promise.resolve(KnowledgeMockAPI.deleteFragment(data));
  }
  return request({
    url: '/document/deletefragment',
    method: 'post',
    data: data
  });
};

export const injecarse = (data: any): Promise<any> => {
  if (USE_MOCK) {
    return Promise.resolve(KnowledgeMockAPI.uploadFile(data));
  }
  return request({
    url: '/document/injecarse',
    method: 'post',
    data: data
  });
};

// 上传知识库文件
export const uploadKbFile = (data: FormData): Promise<any> => {
  return request({
    url: '/kb/add_kbfile',
    method: 'post',
    data: data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
};

// 添加知识库数据
export const addKbData = (data: {
  kb_path: string
  user_id: string
  doc_type: string
  smart_title_parse: boolean
  summary_image: boolean
  summary_table: boolean
  summary_txt: boolean
  file_url: string
  label: string
}): Promise<any> => {
  return request({
    url: '/kb/add_kb_data',
    method: 'post',
    data: data
  });
};

